# Default Dockerfile
#
# @link     https://www.hyperf.io
# @document https://doc.hyperf.io
# @contact  group@hyperf.io
# @license  https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE

FROM hyperf/hyperf:7.4-alpine-v3.11-swoole

##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone
ARG username
ARG useremail

ENV TIMEZONE=${timezone:-"Asia/Shanghai"}
ENV USER_NAME=${username:-"hyperf"}
ENV USER_EMAIL=${useremail:-"group@hyperf.io"}

## 拷贝配置文件
COPY etc /etc/
COPY entrypoint.sh /entrypoint.sh

## 初始化日志目录
RUN mkdir /var/log/supervisor \
    && mkdir /var/log/php \
    && mkdir /var/log/redis

RUN set -ex \
    # update
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk update \
    && apk add --no-cache vim supervisor redis \
    # install composer
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer \
    # show php version and extensions
    && php -v \
    && php -m \
    && php --ri swoole \
    #  ---------- some config ----------
    && cd /etc/php7 \
    # - config PHP
    && { \
        echo "upload_max_filesize=100M"; \
        echo "post_max_size=108M"; \
        echo "memory_limit=1024M"; \
        echo "date.timezone=${TIMEZONE}"; \
    } | tee conf.d/99_overrides.ini \
    # - config timezone
    && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
    && echo "${TIMEZONE}" > /etc/timezone \
    # - config git
    && git config --global user.name ${USER_NAME} \
    && git config --global user.email ${USER_EMAIL} \
    # ---------- clear works ----------
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"

EXPOSE 80

WORKDIR /var/www

ENTRYPOINT ["sh", "/entrypoint.sh"]